﻿function checkCommand(cmdpack: any):any {
    return $.ajax({
        url: "/api/AddUrlsApi",
        type: "POST",
        data: JSON.stringify(cmdpack),
        contentType: "application/json;charset=utf-8",
        dataType: "json",
    });
}

$("#checkUrls").click(() => {
    $('body').addClass('ui-loading');
    $('#checkPane').hide();
    var p: any = { urls: $("#urls").text(), checkOnly:true };
    checkCommand(p)
        .done(function (data) {
            if (data.success) {
                $("#addUrls").show();
            }
            var r:any = data;
            $("#checkedResult").html(r.html);
        })
        .fail(function () {
            alert("server communication error");
        })
        .always(function () {
            $('#checkPane').show();
            $('body').removeClass('ui-loading');
        });
});
$("#addUrls").click(() => {
    $('body').addClass('ui-loading');
    $('#checkPane').hide();
    var p: any = { urls: $("#urls").text(), checkOnly:false };
    checkCommand(p)
        .done(function (data) {
            if (data.success) {
                $("#checkUrls").hide();
                $("#addUrls").hide();
            }
            var r:any = data;
            $("#checkedResult").html(r.html);
        })
        .fail(function () {
            alert("server communication error");
        })
        .always(function () {
            $('#checkPane').show();
            $('body').removeClass('ui-loading');
        });
});

